package services;

import dto.SeoConfigDto;
import models.SeoConfig;
import play.i18n.Lang;

/**
 * Created by Gipxy group
 * Date: 3/17/12
 */
public class SeoConfigService {

    public static SeoConfigDto createDto(SeoConfig app) {
        SeoConfigDto dto = new SeoConfigDto();
        dto.id = app.id;
        dto.language = app.language;
        dto.title = app.title;
        dto.description = app.description;
        dto.keyword = app.keyword;
        dto.page = app.page;

        return dto;
    }

    public static SeoConfig merge(SeoConfigDto dto) {
        SeoConfig merged = null;
        if (dto.id != null) {
            merged = SeoConfig.getByKey(SeoConfig.class, dto.id);
        }
        if (merged == null) {
            merged = new SeoConfig();
        }

        merged.title = dto.title;
        merged.description = dto.description;
        merged.keyword = dto.keyword;
        merged.language = Lang.get();

        merged.page = dto.page;

        merged.save();

        return merged;
    }

}
